# LIBLIST_SEARCH
# --------------
# Define AC_ARG_VAR (user variables), LISTLIB and LISTINC, 
# allowing the user to specify the location of the liblist toolkit 
# library and header file. If not specified, check for these files:
#
#   1. As a sub-project.
#   2. As a super-project (sibling to the current project).
#   3. As installed components on the system.
#
# If found, AC_SUBST LIST_LTLIB and LIST_INCLUDE variables with 
# values derived from LISTLIB and LISTINC user variables.
# LISTLIB and LISTINC are file locations, whereas LIST_LTLIB and 
# LIST_INCLUDE are linker and preprocessor command-line options.
#
# Author:   fulinux <fulinux@sina.com>
# Modified: 2014-09-12
# License:  AllPermissive
#
AC_DEFUN([LIBLIST_SEARCH],
[AC_ARG_VAR([LISTLIB], [The PATH wherein liblist.la can be found])
AC_ARG_VAR([LISTINC], [The PATH wherein list.h can be found])
dnl
# Ensure that both or neither FTK paths were specified.
if { test -n "$LISTLIB" && test -z "$LISTINC"; } || \
   { test -n "$LISTINC" && test -z "$LISTLIB"; } then
  AC_MSG_ERROR([Specify both LISTINC and LISTLIB, or neither.])
fi 

# Not specified? Check for list in standard places.
if test -z "$LISTLIB"; then
  # Check for liblist tool kit as a sub-project.
  if test -d "$srcdir/liblist"; then
    AC_CONFIG_SUBDIRS([liblist])
    LISTINC='$(top_srcdir)/liblist/src'
    LISTLIB='$(top_builddir)/liblist/src'
  else
    # Check for liblist tool kit as a super-project.
    if test -d "$srcdir/../liblist"; then
      LISTINC='$(top_srcdir)/../liblist/src'
      LISTLIB='$(top_builddir)/../liblist/src'
    fi
  fi
fi

# Still empty? Check for *installed* liblist tool kit.
if test -z "$LISTLIB"; then
  AC_CHECK_LIB([list], [can_send], 
    [AC_CHECK_HEADERS([list.h])
     LIBS="-llist $LIBS"],
    [AC_MSG_ERROR([No LIBLIST Toolkit found. Terminating.])])
fi

# AC_SUBST command line variables from LISTLIB and LISTINC.
if test -n "$LISTLIB"; then
  AC_SUBST([LIST_LTLIB], ["$LISTLIB/liblist.la"])
  AC_SUBST([LIST_INCLUDE], ["-I$LISTINC"])
fi[]dnl
])# LIBLIST_SEARCH
